package kc.test.hac;

import java.awt.geom.Point2D;
import java.util.Arrays;
import java.util.logging.Logger;

public class PointVec extends Point2D{
	public static Logger logger = Logger.getLogger(PointVec.class.getName());
	private double[] vec = null;
	
	public String id = null;
	public PointVec(double[] vec) {
		this.vec = vec;
	}
	@Override
	public double getX() {
		throw new UnsupportedOperationException();
	}

	@Override
	public double getY() {
		throw new UnsupportedOperationException();
	}

	@Override
	public void setLocation(double x, double y) {
		throw new UnsupportedOperationException();
	}
	public static double distance(double[] vecA, double[] vecB){
		double docP = 0;
		int length = 0;
		if (vecA.length != vecB.length) {
			logger.info("vecA.length = "+vecA.length+" & vecB.length = "+vecB.length);
		}
		for(length = 0; length<vecA.length&&length<vecB.length; length++){
//			if (java.lang.Double.isNaN(vec[length])) {
//				break;
//			}
//			if (java.lang.Double.isNaN(aVec[length])) {
//				break;
//			}
			length ++;
			docP += vecA[length]*vecB[length];
		}
		double vecLenvth = 0;
		for(int i = 0; i<length; i++){
			vecLenvth += vecA[i]*vecA[i];
		}
		double aVecLength = 0;
		for(int i = 0; i<length; i++){
			aVecLength+= vecB[i]*vecB[i];
		}
		double result = 1-docP/Math.sqrt(vecLenvth*aVecLength);
		if (java.lang.Double.isInfinite(result) || java.lang.Double.isNaN(result)) {
			logger.info(Arrays.toString(vecA));
			logger.info(Arrays.toString(vecB));
			logger.info("result is not good: "+result);
		}
		return result;
	}
	@Override
	public double distance(double px, double py) {
		throw new UnsupportedOperationException();
	}
	@Override
	public double distance(Point2D pt) {
		if (pt instanceof PointVec) {
			return distance(vec, ((PointVec)pt).vec);
		}
		else{
			throw new UnsupportedOperationException();
		}
	}
	@Override
	public double distanceSq(double px, double py) {
		throw new UnsupportedOperationException();
	}
	@Override
	public double distanceSq(Point2D pt) {
		throw new UnsupportedOperationException();
	}
	@Override
	public void setLocation(Point2D p) {
		throw new UnsupportedOperationException();
	}
}
